# Maintainer: David Runge <dave@sleepmap.de>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: SpepS <dreamspepser at yahoo dot it>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: DonVla <donvla@users.sourceforge.net>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - don't build with neon (-DNoNeonPlease=1)

pkgname=zynaddsubfx
pkgver=3.0.5
pkgrel=2
pkgdesc="Opensource software synthesizer capable of making a countless number of instruments."
arch=('x86_64')
url="http://zynaddsubfx.sourceforge.net"
license=('GPL2')
groups=('lv2-plugins' 'pro-audio' 'vst-plugins')
depends=('fftw' 'hicolor-icon-theme' 'liblo' 'libxpm' 'mxml' 'ntk' 'portaudio' 'rtosc')
#makedepends=('asciidoc' 'asciidoctor' 'dblatex' 'cmake' 'doxygen' 'ghostscript' 'gnuplot' 'imagemagick' 'texlive-pictures' 'texlive-pstricks')
makedepends=('asciidoc' 'asciidoctor' 'cmake' 'doxygen')
# tests don't link: https://sourceforge.net/p/zynaddsubfx/bugs/186/
# checkdepends=('cxxtest')
# zyn-fusion is still too fragmented to be build:
# https://github.com/zynaddsubfx/zyn-fusion-issues/issues/214
# https://github.com/zynaddsubfx/zyn-fusion-issues/issues/215
# https://github.com/zynaddsubfx/zyn-fusion-issues/issues/216
# https://github.com/zynaddsubfx/zyn-fusion-issues/issues/217
source=("https://downloads.sourceforge.net/project/${pkgname}/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.bz2"
        "${pkgname}-system-rtosc.patch"
        "${pkgname}-fix-bash-completion-installation.patch")
sha512sums=('1e4d5a6393937e6c7103e6d0e97df76f2d129350854c2f338aa888591091b1508c63e9b52c8e5a176e282ff2f6b72c6a87de54875c412771aff26e8ece2c84e8'
            'e12f6925bc18012a2cee816d94eca51a0e39a9ba020f9692537ba8df839faa954c6dda86a334de59d7c036fa00b77968bae78eb39971a4c58eb126fafafedd7e'
            '667196e5c75286613e6b191645c7edf1e8da6ca54a4e95a34994c3172a0706c1dae48804081299f03cd75b63907f972b2c1ccfa3bb07011cdfda1fd29b21ed69')

prepare() {
  cd "${pkgname}-${pkgver}"
  mkdir -vp build
  # devendor rtosc: https://sourceforge.net/p/zynaddsubfx/bugs/184/
  patch -Np1 -i "../${pkgname}-system-rtosc.patch"
  patch -Np1 -i "../${pkgname}-fix-bash-completion-installation.patch"
}

build() {
  cd "${pkgname}-${pkgver}/build"
  cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DDefaultOutput=jack \
    -DDefaultInput=jack \
    -DGuiModule=ntk \
    -DNoNeonPlease=1 \
    ..
  make VERBOSE=1
  (
  # building only man and html documentation
  # generating a pdf is broken: https://bugs.archlinux.org/task/59778
  # https://sourceforge.net/p/zynaddsubfx/bugs/185/
  cd ../doc
  make man
  make xhtml
  )
}

# check() {
#   cd "${pkgname}-${pkgver}/build"
#   make -k test
# }

package() {
  cd "${pkgname}-${pkgver}/build"
  make DESTDIR="${pkgdir}/" install
  # banks and examples
  install -vd "${pkgdir}/usr/share/${pkgname}"
  cp -va ../instruments/banks "${pkgdir}/usr/share/${pkgname}"
  cp -va ../instruments/examples "${pkgdir}/usr/share/${pkgname}"
  # icons
  install -vDm 644 "../${pkgname}.ico" \
    "${pkgdir}/usr/share/pixmaps/${pkgname}.ico"
  install -vDm 644 "../${pkgname}.svg" \
    "${pkgdir}/usr/share/icons/hicolor/scalable/apps/${pkgname}.svg"
  # man page
  install -vDm 644 "../doc/${pkgname}.1" \
    "${pkgdir}/usr/share/man/man1/${pkgname}.1"
  # documentation
  install -vDm 644 "../doc/${pkgname}.html" \
    "${pkgdir}/usr/share/doc/${pkgname}/${pkgname}.html"
#  install -vDm 644 "../doc/${pkgname}.pdf" \
#    "${pkgdir}/usr/share/doc/${pkgname}/${pkgname}.pdf"
  cp -va ../doc/images "${pkgdir}/usr/share/doc/${pkgname}/"
}
